package l2hc.gameserver.model.instances;

import java.util.StringTokenizer;

import l2hc.gameserver.model.Player;
import l2hc.gameserver.network.serverpackets.NpcHtmlMessage;
import l2hc.gameserver.templates.npc.NpcTemplate;
import l2hc.gameserver.utils.Location;

/**
 * [npc_%objectId%_tele X Y Z|bla bla bla]  NPC 32648
 * @author KilRoy
 */
public final class L2UpdateAnnouncerInstance extends NpcInstance
{
	private static final long serialVersionUID = -1L;
	public L2UpdateAnnouncerInstance(int objectId, NpcTemplate template)
	{
		super(objectId, template);
	}
    
	@Override
	public void showChatWindow(Player player, final int val, Object... arg)
	{
		String filename = val == 0 ? "Announcer/update_announcer001.htm" : "Announcer/update_announcer" + val + ".htm";
		player.sendPacket(new NpcHtmlMessage(player, this, filename, val));
	}

	@Override
	public void onBypassFeedback(Player player, String command)
	{
		if(!canBypassCheck(player, this))
			return;

		NpcHtmlMessage html = new NpcHtmlMessage(player, this);
		StringTokenizer st = new StringTokenizer(command);
		if(st.nextToken().startsWith("tele"))
		{
			if(player.getLevel() < 83)
			{
				html.setFile("Announcer/update_announcer_notp.htm");
				return;
			}
			if(player.getAdena() < 200000)
			{
				html.setFile("Announcer/update_announcer006.htm");
				return;
			}
			player.reduceAdena(200000, true);
			player.teleToLocation(new Location(command.substring(4).trim()));
		}
		super.onBypassFeedback(player, command);
	}
}